package com.one.square.oauth.handler;

import com.one.square.core.domain.Result;
import com.one.square.core.enums.ResultCode;
import org.springframework.http.HttpStatus;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import com.one.square.core.utils.HttpUtils;
import org.springframework.stereotype.Component;

/**
 * @author cwm
 * @Description 授权失败(forbidden)时返回信息
 * @date 2021/10/26 上午10:58
 * @Version 1.0
 */
@Component
public class OneSquareAccessDeniedHandler implements AccessDeniedHandler {
    @Override
    public void handle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AccessDeniedException e) throws IOException, ServletException {
        HttpUtils.writer(Result.failed(HttpStatus.FORBIDDEN.value(), ResultCode.AUTHORIZED_ERROR.getMsg()),httpServletResponse);
    }
}
